package day_2022_9_to_12.Day;

/**
 * @author haomin
 * @date 2022/11/04 20:52
 **/
public class Day62_1_Num754_ReachNumber {
    class Solution {
        public int reachNumber(int target) {
            target = Math.abs(target);
            int sum = 0;
            for(int i = 1; ; ++i){
                sum+=i;
                if(sum >= target){
                    int d = sum - target;
                    if(d % 2 == 0) return i;
                    if((d + i) % 2 == 1) return i+1;
                    else return i+2;
                }
            }
        }
    }
}